import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:wu_you/l10n/messages.dart';
import 'package:wu_you/model/mall/purchase_model.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/utils/utils.dart';
import 'package:wu_you/widgets/button_view.dart';

///我的折扣
class MyDiscountDialog extends StatefulWidget{
  final PurchaseInfo model;
  MyDiscountDialog({Key key,this.model}):super(key: key);
  @override
  MyDiscountDialogState createState() => MyDiscountDialogState();
}
class MyDiscountDialogState extends State<MyDiscountDialog>{
  TextStyle style = TextStyle(fontSize: 16,color: Colors.black);

  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Material(
      color: Colors.transparent,
      child: WillPopScope(
        child: Center(
          child: Padding(
            padding: EdgeInsets.only(left: 40, right: 40),
            child: Container(
              margin: EdgeInsets.only(bottom: 8),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(6)),
                  color: Colors.white
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  ListTile(
                    title: Text("${message['CappingZ']}",style: TextStyle(fontSize: 16,color: Colors.black,fontWeight: FontWeight.bold)),
                    trailing: Text("${message['text63']}",style:  TextStyle(fontSize: 16,color: Colors.black,fontWeight: FontWeight.bold)),
                  ),
                  Column(
                    mainAxisSize: MainAxisSize.min,
                    children: _getItem(widget.model.discountInfo),
                  ),
                  Padding(padding: EdgeInsets.only(left: 30,right: 30,bottom: 12,top: 12),
                    child: ElevatedButtonWidget(
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                        shape: MaterialStateProperty.all(
                            StadiumBorder(
                                side: BorderSide(
                                  style: BorderStyle.solid,
                                  color: AppColors.primaryColor,
                                )
                            )
                        ),
                      ),
                      child: Text("${message['product27']}",style: TextStyle(fontSize: 15,color: Colors.white),),
                      onPressed: (){
                        Navigator.pop(context);

                      },
                    ),
                  )
                ],
              ),
            )
          ),
        ),
        onWillPop: () async {
          return true;
        },
      ),
    );
  }


  List<Widget> _getItem(Map<String,dynamic> map){
    List<Widget> listWidget = [];
    Widget child;
    map.forEach((key, value) {
      child = ListTile(
        title: Text("$key",style: style,),
        trailing: Text("$value",style: style),
      );
      listWidget.add(child);
    });
    return listWidget;
  }
}







///累计返现
class MyCashbackDialog extends StatefulWidget{
  final PurchaseInfo model;
  MyCashbackDialog({Key key,this.model}):super(key: key);
  @override
  MyCashbackDialogState createState() => MyCashbackDialogState();
}
class MyCashbackDialogState extends State<MyCashbackDialog>{
  TextStyle style = TextStyle(fontSize: 16,color: Colors.black);
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    return Material(
      color: Colors.transparent,
      child: WillPopScope(
        child: Center(
          child: Padding(
              padding: EdgeInsets.only(left: 40, right: 40),
              child: Container(
                margin: EdgeInsets.only(bottom: 8),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(6)),
                    color: Colors.white
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    ListTile(
                      title: Text("${message['product42']}",style: TextStyle(fontSize: 16,color: Colors.black,fontWeight: FontWeight.bold)),
                      trailing: Text("${message['product45']}",style:  TextStyle(fontSize: 16,color: Colors.black,fontWeight: FontWeight.bold)),
                    ),
                    Column(
                      mainAxisSize: MainAxisSize.min,
                      children: _getItem(widget.model.cashbackInfo),
                    ),
                    Padding(padding: EdgeInsets.only(left: 30,right: 30,bottom: 12,top: 12),
                      child: ElevatedButtonWidget(
                        style: ButtonStyle(
                          backgroundColor: MaterialStateProperty.all(AppColors.primaryColor),
                          shape: MaterialStateProperty.all(
                              StadiumBorder(
                                  side: BorderSide(
                                    style: BorderStyle.solid,
                                    color: AppColors.primaryColor,
                                  )
                              )
                          ),
                        ),
                        child: Text("${message['product27']}",style: TextStyle(fontSize: 15,color: Colors.white),),
                        onPressed: (){
                          Navigator.pop(context);

                        },
                      ),
                    )
                  ],
                ),
              )
          ),
        ),
        onWillPop: () async {
          return true;
        },
      ),
    );
  }


  List<Widget> _getItem(Map<String,dynamic> map){
    List<Widget> listWidget = [];
    Widget child;
    map.forEach((key, value) {
      child = ListTile(
        title: Text("$key",style: style,),
        trailing: Text("$value",style: style),
      );
      listWidget.add(child);
    });
    return listWidget;
  }
}